const old = [
  {
    balance: 58439.88,
    cid: null,
    id: 1239,
    realName: "pajack",
    refundBalance: null,
    userId: 107415,
    userName: "pajack",
  },
  {
    balance: 500.88,
    cid: null,
    id: 1240,
    realName: "pajack",
    refundBalance: null,
    userId: 107415,
    userName: "pajack",
  },
];

const newData = [
  {
    balance: 58439.88,
    cid: null,
    currentBalance: 58438.88,
    groupId: "",
    id: 1239,
    realName: "pajack",
    refundBalance: "1",
    remark: "",
    userId: 107415,
    userName: "pajack",
  },
];

// 匹配更新旧数组
function dealData(allArr, changeArr) {
  return allArr.map((item) => {
    const temp = changeArr.find((e) => e.id === item.id);
    if (temp) {
      return {
        ...temp, // 使用新数据替换旧数据
      };
    }
    return item;
  });
}

// console.log(dealData(old, newData));

const condition = {
  relation: "and",
  conditions: [],
  filters: [
    { relation: "and", conditions: [], filters: [], filterSort: 2 },
    {
      relation: "and",
      conditions: [
        {
          field: "userName",
          relation: "like",
          function: "like",
          params: ["12"],
          sort: 1,
        },
      ],
      filters: [],
      filterSort: 2,
    },
    {
      relation: "and",
      conditions: [],
      filters: [
        { relation: "and", conditions: [], filters: [], filterSort: 2 },
      ],
      filterSort: 3,
    },
  ],
  filterSort: 0,
};

const filterEmptyCondition = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].conditions.length <= 0 && arr[i].filters.length <= 0) {
      arr.splice(i, 1);
      i--;
    } else {
      if (arr[i].filters && arr[i].filters.length > 0) {
        arr[i].filters = filterEmptyCondition(arr[i].filters);
        if (!arr[i].filters || arr[i].filters.length <= 0) {
          arr.splice(i, 1);
          i--;
        }
      }
    }
  }

  return arr;
};

console.log(filterEmptyCondition(condition.filters));
// console.log(JSON.parse('[{\"code\":\"data\",\"parent\":\"1372839558017959072\",\"type\":\"Map\",\"desc\":\"\"},{\"code\":\"content-type\",\"parent\":\"null.null\",\"type\":\"String\",\"desc\":\"\"},{\"code\":\"code\",\"parent\":\"1372839558017959072.null\",\"type\":\"Int\",\"desc\":\"\"},{\"code\":\"msg\",\"parent\":\"1372839558017959072.null\",\"type\":\"String\",\"desc\":\"\"},{\"code\":\"data\",\"parent\":\"1372839558017959072.null\",\"type\":\"Map\",\"desc\":\"\"},{\"code\":\"x\",\"parent\":\"1372839558017959072.null.null\",\"type\":\"String\",\"desc\":\"\"},{\"code\":\"y\",\"parent\":\"1372839558017959072.null.null\",\"type\":\"String\",\"desc\":\"\"}]'
// ))

[
  {
    code: "data",
    parent: "1372839558017959072",
    type: "Map",
    desc: "",
  },
  {
    code: "content-type",
    parent: "1372839558017959072.header",
    type: "String",
    desc: "",
  },
  {
    code: "code",
    parent: "1372839558017959072.data",
    type: "Int",
    desc: "",
  },
  {
    code: "msg",
    parent: "1372839558017959072.data",
    type: "String",
    desc: "",
  },
  {
    code: "data",
    parent: "1372839558017959072.data",
    type: "Map",
    desc: "",
  },
  {
    code: "x",
    parent: "1372839558017959072.data.data",
    type: "String",
    desc: "",
  },
  {
    code: "y",
    parent: "1372839558017959072.data.data",
    type: "String",
    desc: "",
  },
];
